/**
 * 广寒宫
 * 网址:www.guanghangong.xyz
 */
package com.moon.admin.flowable.entity;

import java.util.Date;
import java.util.ListIterator;

import org.flowable.engine.history.HistoricActivityInstance;
import org.flowable.engine.task.Comment;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.moon.admin.framework.util.ToolUtils;

import lombok.Getter;
import lombok.Setter;

/**
 * 历史环节信息
 * @author ninglong
 */
@Getter
@Setter
public class ActCnHistoricActivityEntity {

	private String id;
	
	private String activityId;

	/** 环节名称 */
	private String activityName;

	private String activityType;

	private String processInstanceId;

	private String executionId;

	private String taskId;

	private String tenantId;

	/** 执行人 */
	private String assignee;

	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date startTime;
	@JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss")
	private Date endTime;

	private String deleteReason;
	
	/** 办理意见 */
	private String comment;


	public ActCnHistoricActivityEntity() {
		super();
	}

	public ActCnHistoricActivityEntity(HistoricActivityInstance hai, ListIterator<Comment> it){
		this.setId(hai.getId());
		activityId = hai.getActivityId();
		activityName = hai.getActivityName();
		activityType = hai.getActivityType();
		if("startEvent".equals(activityType)) {//开始节点
			activityName = ToolUtils.isEmpty(activityName) ? "开始" : activityName;
		}
		if("endEvent".equals(activityType)) {//结束节点
			activityName = ToolUtils.isEmpty(activityName) ? "结束" : activityName;
		}
		if("userTask".equals(activityType)) {//用户任务节点
			activityName = ToolUtils.isEmpty(activityName) ? "用户任务" : activityName;
		}
		processInstanceId = hai.getProcessInstanceId();
		taskId = hai.getTaskId();
		executionId = hai.getExecutionId();
		tenantId = hai.getTenantId();
		assignee = hai.getAssignee();
		startTime = hai.getStartTime();
		endTime = hai.getEndTime();
		deleteReason = hai.getDeleteReason();
		if(it != null) {
			while (it.hasNext()) {
				comment += it.next().getFullMessage();
				comment = comment.replace("null", "");//null字符串的坑
				comment = comment.replace("NULL", "");
			}
		}
	}
}